﻿using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using TrackIT.Common.Factories;

namespace TrackIT.UnitTest
{
    [ExcludeFromCodeCoverage]
    internal sealed class MockWorkStreamFactory : IWorkStreamFactory
    {
        MemoryStream _buffer;
        string _tasksBuffer;
        
        public string TasksBuffer
        {
            set
            {
                _tasksBuffer = value;
            }
        }

        public Stream CreateStream(string filename)
        {
            if (!string.IsNullOrEmpty(_tasksBuffer))
            {
                byte[] array = Encoding.ASCII.GetBytes(_tasksBuffer);
                _buffer = new MemoryStream(array, true);
                _buffer.Seek(0, SeekOrigin.Begin);
            }
            else
            {
                _buffer = new MemoryStream();                
            }
            return _buffer; 
        }
    }
}
